package com.aliyun.oss.controller;

import com.aliyun.oss.pojo.Result;
import com.aliyun.oss.pojo.User;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpSession session){
        Result result = new Result();
        if(user!=null&&"123".equals(user.getPassword())){
            result.setFlag(true);
//            System.out.println("user = " + user);
            session.setAttribute("user",user.getUsername());
        }else {
            result.setFlag(false);
            result.setMessage("用户名或密码错误");
        }
        return result;
    }
    @GetMapping("/getUsername")
    public Result getUsername(HttpSession httpSession){
        String user = (String) httpSession.getAttribute("user");
//        System.out.println("user = " + user);
        return new Result(true,user,null);
    }
}
